//
//  MaterialTableViewCell.m
//  Cook
//
//  Created by 0.0 on 15-4-14.
//  Copyright (c) 2015年 dingjun. All rights reserved.
//

#import "MaterialTableViewCell.h"
#import "CookMethod.h"
#import "DMView.h"

@interface MaterialTableViewCell ()
{
    CGAdapter _myAdapter;
}
@end

@implementation MaterialTableViewCell

- (void)dealloc
{
    [_materialImage release];
    [_materialLabel release];
    [_materialLabelView release];
    
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        _myAdapter = [AdapterModel getCGAdapter];
        self.frame = CGRectMake(0, 0, MainWidth, self.frame.size.height);
        self.contentView.backgroundColor = [UIColor colorWithRed:247 / 255.0 green:227 / 255.0 blue:171 / 255.0 alpha:1.0];
        [self getImage];
        [self getView];
    }
    
    return self;
}

- (void)getView
{
    self.frame = CGRectMake(0, 0, MainWidth, self.frame.size.height);
    
    self.materialLabelView = [[DMView alloc] initWithFrame:CGRectMake(self.frame.origin.x + 40, self.frame.origin.y + 10, (self.frame.size.width - 80) * _myAdapter.sWidth, 170 * _myAdapter.sHeight)];

    [self.contentView addSubview:_materialLabelView];
    [_materialLabelView release];

    
}

- (void)getImage
{
    self.frame = CGRectMake(0, 0, MainWidth, self.frame.size.height);
    self.materialImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.origin.x + 40., self.frame.origin.y + 10, (self.frame.size.width - 80) * _myAdapter.sWidth, 150 * _myAdapter.sHeight)];
    self.frame = CGRectMake(_materialImage.frame.origin.x, _materialImage.frame.origin.y, _materialImage.frame.size.width, _materialImage.frame.size.height + self.materialImage.frame.size.height / 4);
    
    _materialImage.layer.borderWidth = 0.05f;
    _materialImage.layer.shadowOffset = CGSizeMake(0, 0);
    _materialImage.layer.shadowColor = [UIColor grayColor].CGColor;
    _materialImage.layer.shadowOpacity = 0.8;
    _materialImage.layer.shadowRadius = 5.0f;
    
    [self.contentView addSubview:_materialImage];
    
    [_materialImage release];
}


- (UILabel *)materialLabel
{
    self.frame = CGRectMake(0, 0, MainWidth, self.frame.size.height);
    if (_materialLabel == nil) {
        _materialLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, (self.bounds.size.width + 20) * _myAdapter.sWidth, 0)];
        _materialLabel.numberOfLines = 0;
        _materialLabel.font = [UIFont systemFontOfSize:18.0f];
        _materialLabel.textAlignment = NSTextAlignmentNatural;
        [self.contentView addSubview:_materialLabel];
        [_materialImage release];
        
    }
    
    return [[_materialLabel retain] autorelease];
}




//- (void)setTextOfMaterialLabel:(NSString *)text
//{
//    
//    // 如果没有文字就不显示label
//    if (!self.materialLabel.text) {
//        self.materialLabel.frame = CGRectZero;
//    }
//    
//    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:18.0f]};
//    CGRect rect = [_materialLabel.text boundingRectWithSize:CGSizeMake(self.frame.size.width, 100000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
//    _materialLabel.frame = CGRectMake(_materialLabel.frame.origin.x, _materialLabel.frame.origin.y, rect.size.width, rect.size.height + 50);
//    _materialLabel.numberOfLines = 0;
//    _materialLabel.font = [UIFont systemFontOfSize:18.0f];
////    _materialLabel.textAlignment = NSTextAlignmentCenter;
//    
//    self.frame = _materialLabel.frame;
//    [_materialLabel release];
//  
//}
//
//- (void)getImageWithPath:(NSString *)path text:(NSString *)text
//{
//
//    
//}
//




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
